package com.ayq.activiti.manager.controller;

import com.ayq.activiti.manager.service.CustomModelService;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.activiti.editor.constants.ModelDataJsonConstants;
import org.activiti.engine.ActivitiException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/service")
@Api(tags = "流程模型web配置中心")
@Slf4j
public class ModelEditorJsonRestResource implements ModelDataJsonConstants {

    protected static final Logger LOGGER = LoggerFactory.getLogger(ModelEditorJsonRestResource.class);

    @Autowired
    private CustomModelService customModelService;

    /**
     * <p>获取编辑流程模型信息</p>
     * <p>方法名:getEditorJson</p>
     *
     * @Author ayq
     * @Date 2021/3/8 16:13
     * @Param [modelId]
     * @Return com.fasterxml.jackson.databind.node.ObjectNode
     */
    @ApiOperation(value = "获取编辑流程模型信息", notes = "获取编辑流程模型信息")
    @RequestMapping(value = "/model/{modelId}/json", method = RequestMethod.GET, produces = "application/json")
    public ObjectNode getEditorJson(@PathVariable String modelId) {
        ObjectNode modelNode = null;
        try {
            return customModelService.getEditorJson(modelId, modelNode);
        } catch (Exception e) {
            LOGGER.error("获取流程模型数据出错", e);
            throw new ActivitiException("获取流程模型数据出错", e);
        }
    }
}
